package likou;

import java.util.Arrays;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/07/19 11:07
 */
public class _1838 {
    public static void main(String[] args) {
        System.out.println(maxFrequency(new int[]{1,4,8,13,7,10,7,5,75,12},25));
    }
    public static int maxFrequency(int[] nums, int k) {
        int n=nums.length;
        int res=0;
        Arrays.sort(nums);
        int r=n-1;
        for(int i=n-2;i>=0;i--){
            if(k>=0){
                res=Math.max(r-i,res);
                k-=nums[r]-nums[i];
            }else{
                k+=(nums[r]-nums[r-1])*(r-i-1);
                r--;i++;
            }
        }
        if(k>=0)res=Math.max(r+1,res);
        return res;
    }
}
